﻿using System;

class Angry_Bits
{
    static void Main()
    {
        int[,] grid = new int[10, 17];                      // Filling the array with "0"

        // Console input
        for (int row = 1; row < 9; row++)
        {
            int temp = int.Parse(Console.ReadLine());

            // Filling the array with "1" according to the binary representation of the number
            for (int col = 1; col < 17; col++)
            {
                if (((1 << (col - 1)) &  temp) != 0 )       // Check every bit if it is "1" or "0"
                {
                    grid[row, col] = 1;
                }
            }
        }

        // Start
        int result = 0;

        for (int col = 9; col < 17; col++)                  // Start of the search for birds in their half: columns 9 - 16
        {
            bool birdFound = false;

            for (int row = 1; row < 9; row++)               // Checking every cell in each column
            {
                if (grid[row, col] == 1)                    // A bird is found
                {
                    birdFound = true;

                    grid[row, col] = 0;                     // After the end of its flight each bird dies and is removed from the grid

                    int nextRow = row;
                    int nextCol = col;
                    int flightLength = 0;
                    int pigsKilled = 0;
                    bool upwards = true;

                    for (int i = col; i > 0 ; i--)          // Start of the bird's flight in direction to the last column
                    {                        
                        if (nextRow > 1 && upwards)         // Flying upwards
                        {
                            if (nextRow == 2)
                            {
                                upwards = false;            // Direction change
                            }
                            nextRow -= 1;
                            nextCol -= 1;
                        }
                        else                                // Flying downwards
                        {
                            upwards = false;
                            if (nextRow == 7)               // The bird is one row before reaching the bottom and the next cycle must not be executed
                            {
                                i = 1;                      // Going to the end of the cycle counter
                            }
                            nextRow += 1;
                            nextCol -= 1;
                        }

                        flightLength++;

                        if (grid[nextRow, nextCol] == 1)    // A pig is found              
                        {
                            for (int k = nextRow - 1; k <= nextRow + 1; k++)            // Checking all cells around the pig for other pigs
                            {                                                           // For example:
                                for (int j = nextCol + 1; j >= nextCol - 1; j--)        //
                                {                                                       // 1 0 0    Three pigs found
                                    pigsKilled += grid[k, j];                           // 0 1 1
                                    grid[k, j] = 0;                                     // 0 0 0
                                }                                                       //
                            }                                                           // After a pig is killed it is removed from the grid

                            result += flightLength * pigsKilled;
                            break;                          // The birds' flight ends
                        }
                    }

                    if (birdFound)
                    {
                        break;                              // There could be only one bird in each column
                    }
                }
            }
        }
                
        // Check if there are more pigs left

        for (int row = 1; row < 9; row++)
        {
            for (int col = 1; col < 9; col++)
            {
                if (grid[row, col] == 1)
                {
                    Console.WriteLine(result + " No");
                    return;
                }
            }
        }

        Console.WriteLine(result + " Yes");
    }
}